package com.xiyu.service.controller.admin.order;
import com.xiyu.service.vo.sales.SalesCancelInput;
import com.xiyu.service.vo.sales.SalesSingleGetOutput;
import com.xiyu.service.vo.sales.SalesCheckInput;
import com.xiyu.service.vo.sales.SalesUpdateInput;
import com.xiyu.service.vo.sales.SalesCreateInput;
import com.xiyu.service.vo.sales.SalesPageQueryOutput;
import com.xiyu.service.vo.sales.SalesPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.order.SalesService;

@Tag(name = "销售订单")
@RestController
@RequestMapping("/order/sales")
@Validated
public class SalesController {

    @Resource
    private SalesService salesService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询")
    @PreAuthorize("@ss.hasPermission('order:sales:list')")
    public CommonResult<PageResult<SalesPageQueryOutput>> pageQuery(@Valid SalesPageQueryInput inputVO) {
        return success(salesService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增销售订单")
    @PreAuthorize("@ss.hasPermission('order:sales:create')")
    public CommonResult<Boolean> create(@Valid @RequestBody SalesCreateInput inputVO) {
        return success(salesService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新销售订单")
    @PreAuthorize("@ss.hasPermission('order:sales:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody SalesUpdateInput inputVO) {
        return success(salesService.update(inputVO));
    }

    @PostMapping("/check")
    @Operation(summary = "审核销售订单")
    @PreAuthorize("@ss.hasPermission('order:sales:check')")
    public CommonResult<Boolean> check(@Valid @RequestBody SalesCheckInput inputVO) {
        return success(salesService.check(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个销售订单")
    @Parameter(name = "id", description = "客户信息主键ID", example = "")
    public CommonResult<SalesSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(salesService.singleGet(id));
    }

    @PostMapping("/cancel")
    @Operation(summary = "取消销售订单")
    @PreAuthorize("@ss.hasPermission('order:sales:cancel')")
    public CommonResult<Boolean> cancel(@Valid @RequestBody SalesCancelInput inputVO) {
        return success(salesService.cancel(inputVO));
    }

}
